package com.gupaoedu.design.template.task;

import com.gupaoedu.design.template.task.entity.ApplyHoliday;
import com.gupaoedu.design.template.task.entity.Employee;
import com.gupaoedu.design.template.task.factory.CompanyFactory;
import com.gupaoedu.design.template.task.factory.PersonFactory;

import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
 * <p></p>
 *
 * @author Andy
 * @date 2018/3/13.
 */
public class CompanyTemplate {
    private CompanyFactory factory = new PersonFactory();

    public int applyHoliday(Employee employee) {
        //1、小明需要请假，首先需要自己进行请假填单
        ApplyHoliday holiday = writeApplyHoliday(employee);

        //2、项目经理需要签字
        int code = factory.projectManagerWork(holiday).getHoliday().getCode();
        if (code == 2) {
            return code;
        }

        //3、部门经理需要签字
        code = factory.departmentManagerWork(holiday).getHoliday().getCode();
        if (code == 2) {
            return code;
        }

        //4、人事经理需要签字
        code = factory.personnelManagerWork(holiday).getHoliday().getCode();
        if (code == 2) {
            return code;
        }

        //5、将请好假的单子送到人事专员手中
        giveApplyHolidayHRSpecialist(holiday);

        return code;
    }

    /**
     * 自己填写请假单
     *
     * @param employee
     * @return
     */
    private ApplyHoliday writeApplyHoliday(Employee employee) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        ApplyHoliday holiday = new ApplyHoliday();
        holiday.setuId(employee.getuId());
        holiday.setNumber("2018031400001");
        holiday.setReason("有事外出");
        holiday.setCurrentProcess(employee.getRole());
        try {
            holiday.setHolidayStartDate(sdf.parse("2018-03-14 14:00:00"));
            holiday.setHolidayEndDate(sdf.parse("2018-03-16 18:00:00"));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return holiday;
    }

    private void giveApplyHolidayHRSpecialist(ApplyHoliday holiday) {
        System.out.println("已经交给人事专员");
        System.out.println("请假成功");
        System.out.println(holiday);
    }
}
